<?php
require_once 'util/class.daofactory.php';

class DiscoveryListService {
	
	public function getlist($tagIds, $pageIndex) {
		$result = array();
		if(!$tagIds|| count($tagIds)==0
				|| !is_int($pageIndex) || $pageIndex<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		$len = count($tagIds);
		$notesList=array();
		global $discoveryDao;
		for($i=0; $i<$len; $i+=2) {
			$tagId = $tagIds[$i];
			$sinceNoteId = $tagIds[$i+1];
			
			$discoveryList = $discoveryDao->getDiscoveryList($tagId, 
					Constants::$DISCOVERY_PAGE_SIZE, $sinceNoteId);
			if(!$discoveryList)
				continue;
			
			$notesList[]=array('typeId'=>$tagId, 'data'=>$discoveryList);
		}
		
		// return the data
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>$notesList);
		return $result;
	}
	
}